package handler

import (
	"encoding/json"
	"github.com/keepfoo/minirest/logger"
	"io/ioutil"
	"net/http"
)

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Captcha  string `json:"captcha"`
}

type User struct {
	Id            string `json:"id"`
	ContactIdList string `json:"contactIdList"`
	Date          string `json:"date"`
	Head          string `json:"head"`
	Name          string `json:"name"`
	PictureList   string `json:"pictureList"`
	Sex           string `json:"sex"`
	Tag           string `json:"tag"`
}

//TODO
func LoginHandler(w http.ResponseWriter, r *http.Request) {
	if data, err := ioutil.ReadAll(r.Body); err != nil {
		logger.Error("请求参数有问题: " + err.Error())
		w.WriteHeader(http.StatusBadRequest)
		return
	} else {
		var loginReq LoginRequest
		if err = json.Unmarshal(data, &loginReq); err != nil {
			logger.Error("请求体 JSON 格式有问题: " + err.Error())
			w.WriteHeader(http.StatusBadRequest)
			return
		}
		loginReq.Password = "xxx"
		RenderJson(w, loginReq)
	}
}
